<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 400px;
            height: 300px;
            border: 2px solid blue;
            margin: 100px auto;
        }

        input {
            margin-left: 70px;
            margin-bottom: 10px;
            width: 250px;
            height: 30px;
            border: 0.5;
            /* border-radius: 2%; */
        }

        button {
            width: 250px;
            height: 30px;
            margin-left: 70px;
            background-color: blue;
            color: white;
            font-weight: 400;
            border: 0;
            font-size: 18px;
        }

        .box .c1 {
            margin-top: 50px;
        }

        .box .c3 {
            margin-left: 250px;
            color: blue;
            margin-bottom: 10px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="c1"><input type="text" placeholder="手机号/用户名/邮箱"></div>
        <div> <input type="password" placeholder="密码"></div>
        <div class="c3">忘记密码？</div>
        <button>登录</button>
    </div>
</body>

</html>
<script src="./ajax.js"></script>
<script>
    var input = document.querySelectorAll('.box input')
    var btn = document.querySelector('.box button')
    btn.onclick = function () {
        if (input[0].value && input[1].value) {
            if (/^\d{4}/.test(input[1].value)) {
                ajax('get', 'https://yantianfeng.com/api/login', { username: input[0].value, password: input[1].value }).then((data) => {
                    if (data.status == 400) {
                        alert(data.msg)
                    } else {
                        alert(data.msg)
                    }
                })
            } else {
                alert('密码格式不正确')
            }
        } else {
            alert('手机号/密码不能为空')
        }
    }

</script>